VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Begin VB.Form FrmLogin 
   BackColor       =   &H00800000&
   Caption         =   "Login"
   ClientHeight    =   2880
   ClientLeft      =   3360
   ClientTop       =   2280
   ClientWidth     =   5100
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2880
   ScaleWidth      =   5100
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   375
      Left            =   2040
      Top             =   240
      Visible         =   0   'False
      Width           =   2055
      _ExtentX        =   3625
      _ExtentY        =   661
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "Adodc1"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.CommandButton cmdExit 
      Caption         =   "&Exit"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   360
      Left            =   2160
      TabIndex        =   4
      Top             =   2310
      Width           =   1110
   End
   Begin VB.PictureBox Picture1 
      BackColor       =   &H00E0E0E0&
      Height          =   1440
      Left            =   240
      ScaleHeight     =   1380
      ScaleWidth      =   4635
      TabIndex        =   0
      Top             =   705
      Width           =   4695
      Begin VB.TextBox txtUserName 
         Height          =   350
         Left            =   1920
         TabIndex        =   1
         Top             =   120
         Width           =   1335
      End
      Begin VB.TextBox m_WorkingDate 
         Alignment       =   2  'Center
         Height          =   350
         Left            =   1920
         TabIndex        =   3
         Top             =   930
         Width           =   1365
      End
      Begin VB.TextBox Psw 
         ForeColor       =   &H00800080&
         Height          =   350
         IMEMode         =   3  'DISABLE
         Left            =   1920
         PasswordChar    =   "*"
         TabIndex        =   2
         Top             =   480
         Width           =   1350
      End
      Begin VB.Label Label5 
         BackStyle       =   0  'Transparent
         Caption         =   "Working date"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800000&
         Height          =   285
         Left            =   165
         TabIndex        =   7
         Top             =   915
         Width           =   1620
      End
      Begin VB.Label Label2 
         BackStyle       =   0  'Transparent
         Caption         =   "Password"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800000&
         Height          =   285
         Left            =   165
         TabIndex        =   6
         Top             =   510
         Width           =   1650
      End
      Begin VB.Label Label1 
         BackStyle       =   0  'Transparent
         Caption         =   "User"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00800000&
         Height          =   285
         Left            =   225
         TabIndex        =   5
         Top             =   120
         Width           =   1710
      End
   End
   Begin VB.Label Label3 
      BackStyle       =   0  'Transparent
      Caption         =   "Login"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   18
         Charset         =   0
         Weight          =   700
         Underline       =   -1  'True
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00E0E0E0&
      Height          =   540
      Left            =   60
      TabIndex        =   8
      Top             =   -30
      Width           =   1920
   End
End
Attribute VB_Name = "FrmLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub cmdExit_Click()
'Adodc1.Recordset.Close
Unload Me
End

End Sub


Private Sub Form_Activate()
    txtUserName.SetFocus
    m_WorkingDate = Format(Date, "dd/mm/yyyy")
    WorkingDate = m_WorkingDate
End Sub

Private Sub m_WorkingDate_KeyPress(KeyAscii As Integer)
On Error GoTo trove
If KeyAscii = 13 Then
    WorkingDate = CDate(Format(m_WorkingDate, "dd/mm/yyyy hh:mm:ss"))
    FrmLogin.Hide
    
End If
trove:
    If Err.Number > 0 Then
        MsgBox "Nhap lai ngay"
        m_WorkingDate.SetFocus
    End If
End Sub
Private Sub psw_KeyPress(KeyAscii As Integer)
On Error GoTo Err_action


If KeyAscii = 13 Then
    Set DBconn = New Connection
    DBconn.ConnectionTimeout = 10
    ConnectString = "Provider=SQLOLEDB;Driver={SQL Server};Server=" & ServerName & ";" & _
    "Database=" & DBName & ";UID=" & txtUserName & ";PWD=" & Psw
    DBconn.ConnectionString = ConnectString
    DBconn.Open
'Ket noi thanh cong
    If DBconn.State = adStateOpen Then
        Adodc1.ConnectionString = ConnectString
        Adodc1.ConnectionTimeout = 40
        Adodc1.CommandType = adCmdText
        Adodc1.RecordSource = "Select Users.* from Users where UserName='" & txtUserName & "'"
        Adodc1.Refresh
        If Adodc1.Recordset.RecordCount < 1 Then
            MsgBox "Chua thiet lap menu cho user nay"
            DBconn.Close
            txtUserName = ""
            Psw = ""
            txtUserName.SetFocus
        Else
            usercodeLogin = Adodc1.Recordset("usercode")
            UserLogin = Adodc1.Recordset("UserName")
            TenLogin = Adodc1.Recordset("Name")
            NhomLogin = Adodc1.Recordset("UserGroup")
            
            Adodc1.Recordset.Close
            FrmLogin.Tag = UserLogin
            m_WorkingDate.SetFocus
        End If
    Else
        MsgBox "Username hay password khong dung"
        Psw = ""
        Psw.SetFocus
        Exit Sub
    End If
End If

Next_Action:
   Exit Sub
Err_action:
    MsgBox "Username hay password khong dung"
    Psw = ""
    Psw.SetFocus
    Resume Next_Action

End Sub



Private Sub txtUserName_KeyPress(KeyAscii As Integer)
On Error GoTo Err_action


If KeyAscii = 13 Then
    Set DBconn = New Connection
    DBconn.ConnectionTimeout = 10
    ConnectString = "Provider=SQLOLEDB;Driver={SQL Server};Server=" & ServerName & ";" & _
    "Database=" & DBName & ";UID=" & txtUserName & ";PWD=" & Psw
    DBconn.ConnectionString = ConnectString
    DBconn.Open
'Ket noi thanh cong
    If DBconn.State = adStateOpen Then
        Adodc1.ConnectionString = ConnectString
        Adodc1.ConnectionTimeout = 40
        Adodc1.CommandType = adCmdText
        Adodc1.RecordSource = "Select Users.* from Users where UserName='" & txtUserName & "'"
        Adodc1.Refresh
        If Adodc1.Recordset.RecordCount < 1 Then
            MsgBox "Chua thiet lap menu cho user nay"
            DBconn.Close
            txtUserName = ""
            Psw = ""
            txtUserName.SetFocus
        Else
            usercodeLogin = Adodc1.Recordset("usercode")
            UserLogin = Adodc1.Recordset("UserName")
            TenLogin = Adodc1.Recordset("Name")
            NhomLogin = Adodc1.Recordset("UserGroup")
            
            Adodc1.Recordset.Close
            FrmLogin.Tag = UserLogin
            m_WorkingDate.SetFocus
        End If
    Else
        MsgBox "Username hay password khong dung"
        Psw = ""
        Psw.SetFocus
        Exit Sub
    End If
End If

Next_Action:
   Exit Sub
Err_action:
    MsgBox "Username hay password khong dung"
    Psw = ""
    Psw.SetFocus
    Resume Next_Action
End Sub

